<?php
	class Default_Model_DbTable_Navigation extends Zend_Db_Table_Abstract
	{
	    protected $_name = 'site_navigation';
	    protected $_sequence = '_seq_site_navigation';

	    protected $_primary = 'id';
	    protected $_pk = 'id';


	    public function getModuleDefaultRoles()
	    {
            $array = array(
                'backend'       =>'administrator',
                'coordinators'  =>'local-coordinator',
                'default'       =>'member',
                'foreign-institutions'  =>'foreign-institution',
                'incoming-students'     =>'incoming-student',
                'outgoing-staff'        =>'outgoing-staff',
                'outgoing-students'     =>'outgoing-student',

            );
	        return $array;

	    }

	    public function getModuleDefaultRole($moduleName='unknown')
	    {
            $moduleRoles = $this->getModuleDefaultRoles();
            $defaultRole = $moduleRoles[$moduleName];
	        return $defaultRole;

	    }

	    public function getNavigation($id, $returnArray = false)
	    {
	        $id = (int)$id;
	    	$row = $this->fetchRow($this->_pk .'= '. $id);
	        if (!$row) {
	            throw new Exception("Count not find row $id");
	        }
	        if ($returnArray == true) {
		        return $row->toArray();
	        }
	        return $row;

	    }

	    public function findNavigation($module, $controller, $action, $returnArray = false)
	    {
	    	$where = $this->select()
			        ->where('module_name = ?', $module)
			        ->where('controller_name = ?', $controller)
			        ->where('action_name = ?', $action)
			      	;

			      	//echo $where;
			$row = $this->fetchRow($where);
	    	//$row = $this->fetchRow('module= '. $module);
	        if (!$row) {
	            return false;
	        }
	        if ($returnArray == true) {
		        return $row->toArray();
	        }
	        return $row;

	    }

	    public function addNavigation($data)
	    {

	        $this->insert($data);
	        $id = $this->_db->lastInsertId($this->_name);
	        return $id;
	    }

	    public function updateNavigation($id, $data)
	    {
	        $this->update($data, $this->_pk . ' = ' . (int)$id);

	    }

	    public function deleteNavigation($id)
	    {
	        $this->delete($this->_pk .'=' . (int)$id);
	    }
	}